package com.hongxun.design.jungong.dialog;

import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;

import com.hongxun.design.R;
import com.hongxun.design.bean.CodeSetBean;

/**
 * Created by Administrator on 2017/8/11.重命名已有典设
 */

public class ModeleNameDialog extends DialogFragment {
    private AlertDialog dialogm;
    private CodeSetBean setBean;

    public interface reName {
        void renameandnumber(String name, String number);
    }

    public ModeleNameDialog() {

    }

    public void setSetBean(CodeSetBean setBean) {
        this.setBean = setBean;
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        LayoutInflater inflater = getActivity().getLayoutInflater();
        View view = inflater.inflate(R.layout.renamedialog, null);
        final EditText etname = (EditText) view.findViewById(R.id.rename_et_name);
        final EditText etnumber = (EditText) view.findViewById(R.id.rename_et_number);
        etname.setText(setBean.getName());
        etnumber.setText(setBean.getNumber());
        view.findViewById(R.id.rename_btn_yes).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialogm.dismiss();
                String name = String.valueOf(etname.getText()).trim();
                String number = String.valueOf(etnumber.getText()).trim();
                reName listener = (reName) getActivity();
                listener.renameandnumber(name, number);
            }
        });
        view.findViewById(R.id.rename_btn_no).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialogm.dismiss();
            }
        });
        dialogm = builder.create();
        dialogm.setView(view, 0, 0, 0, 0);
        return dialogm;
    }
}
